package com.lx.idea.controller;

import com.lx.idea.common.Constant;
import com.lx.idea.common.dto.ResponseModel;
import com.lx.idea.service.AnalysisServiceImpl;
import com.lx.idea.service.ESService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Author ybb
 * @Description
 * @Date 2021/9/27 15:41
 */
@RestController
@RequestMapping("/statistic")
public class StatCountController {

    @Value("${es.index}")
    String index;

    @Autowired
    AnalysisServiceImpl analysisService;

    @Autowired
    ESService esService;

    @GetMapping("/analysis")
    public ResponseModel analysisCount(){
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        long time = 86400000 * 7;
        Date date = new Date();
        long end = date.getTime()-time;
        String minDate = sdf2.format(new Date(end));
        String maxDate = sdf2.format(date);
        return ResponseModel.success(esService.analysisCount(index,Constant.MoStatInfo,minDate,maxDate));
    }

    @GetMapping("/register")
    public ResponseModel RegisterCount(){
        long time = 86400000 * 7;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date();
        long end = date.getTime()-time;
        String minDate = sdf.format(new Date(end));
        String maxDate = sdf.format(date);
        return ResponseModel.success(analysisService.registerCount(minDate,maxDate));
    }
}
